<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>SUOYUEの后台管理系统</title>

  <link rel="shortcut icon" th:href="@{/images/favicon.ico}" />
  <link rel="stylesheet" href="../../static/lib/Semantic-UI/semantic.min.css" th:href="@{/lib/Semantic-UI/semantic.min.css}">
  <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
</head>

<body>
  <!--导航栏-->
  <nav class="ui inverted gird-header" >
    <div class="ui container">
      <div class="ui inverted secondary stackable menu">
        <h2 class="ui olive header item" style="font-family: STSong"><span th:text="${session.admin.username}">SUOYUE</span>の后台管理</h2>
        <a href="#" th:href="@{/admin/users}" class="m-item item m-mobile-hide"><i class="users icon"></i>用户管理</a>
        <a href="#" th:href="@{/admin/blogs}" class="active m-item item m-mobile-hide"><i class="map icon"></i>文章管理</a>
        <div class="right m-item m-mobile-hide menu">
          <div class="ui dropdown item">
            <div class="text">
              <img class="ui avatar image" src="../../static/images/me.jpg" th:src="${session.admin.avatar}">
              <span th:text="${session.admin.username}">suoyue_zhan</span>
            </div>
            <i class="dropdown icon"></i>
            <div class="menu">
              <a href="" th:href="@{/admin/logout}" class="item">注销</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--手机端收起导航栏-->
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
      <i class="sidebar icon"></i>
    </a>
  </nav>

  <div class="m-padded-tb-hugex"></div>


  <!--中间内容-->
  <div  class="m-padded-tb-mini">
    <div class="ui container">
      <!--提示信息-->
      <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
        <i class="close icon"></i>
        <div class="header">提示：<span th:text="${message}" style="color: #FF0000">三思后行-有始有终</span></div>
      </div>
      <!--搜索栏-->
      <div class="ui secondary segment form">
        <input type="hidden" name="page" >
        <div class="inline fields">
          <div class="field">
            <input type="text" name="title" placeholder="标题">
          </div>
          <div class="field">
            <div class="ui labeled action input">
              <div class="ui type selection dropdown">
                <input type="hidden" name="userId">
                <i class="dropdown icon"></i>
                <div class="default text">用户</div>
                <div class="menu">
                  <div th:each="user: ${users}" class="item" data-value="1" th:data-value="${user.id}" th:text="${user.username}">我的故事</div>
                </div>
              </div>
              <button id="clear-btn" class="ui compact button">clear</button>
            </div>
          </div>
          <div class="field">
            <button type="button" id="search-btn" class="ui small teal basic button"><i class="search icon"></i>搜索</button>
          </div>
        </div>
      </div>
      <!--内容展示-->
      <div id="table-container">
        <table class="ui compact teal table" th:fragment="blogList">
          <thead>
            <tr align="center">
              <th >ID</th>
              <th >标题</th>
              <th>链接</th>
              <th>状态</th>
              <th>更新时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr th:each="blog: ${pageInfo}" align="center">
              <td th:text="${blog.id}">1</td>
              <td th:text="${blog.title}">大圣，此去欲何?</td>
              <td><a th:href="${blog.url}" target="_blank" th:text="${blog.url}">大圣，此去欲何?</a></td>
              <td th:text="${blog.recommend} ? '可见' : '屏蔽'">推荐</td>
              <td th:text="${#dates.format(blog.updateTime,'yyy-MM-dd HH:mm')}">2020-01-02 05:20</td>
              <td>
                <a href="#" th:href="@{/admin/blog/release/{id}/{enabled}(id=${blog.id},enabled=${blog.recommend})}" class="ui tiny inverted teal button">解禁</a>
                <a href="#" th:href="@{/admin/blog/disable/{id}/{enabled}(id=${blog.id},enabled=${blog.recommend})}" class="ui tiny inverted brown button">屏蔽</a>
                <a href="#" th:href="@{/admin/blog/delete/{id}(id=${blog.id})}" onclick="return confirm('确定要删除该文章吗？三思啊! 删了可就没了！')"  class="ui tiny inverted red  button">删除</a>
              </td>
            </tr>
          </tbody>

          <tfoot>
          <tr>
            <th colspan="7">
              <div class="ui inverted divided stackable grid">
                <div class="three wide column" align="center">
                  <a th:href="@{/admin/blogs(pageNum=${pageInfo.pageNum}-1)}" class="item">上一页</a>
                </div>

                <div class="ten wide column" align="center">
                  <p>第 <span th:text="${pageInfo.pageNum}"></span> 页，共 <span th:text="${pageInfo.pages}"></span> 页，有 <span th:text="${pageInfo.total}"></span> 篇文章</p>
                </div>

                <div class="three wide column" align="center">
                  <a th:href="@{/admin/blogs(pageNum=${pageInfo.pageNum}+1)}" class="item">下一页</a>
                </div>
              </div>
            </th>
          </tr>
          </tfoot>
        </table>

      </div>
    </div>
  </div>


  <br>
  <br>
  <br>
  <br>
  <br>
  <br>
  <br>
  <br>
  <br>

  <!--底部栏-->
  <footer class="ui inverted vertical segment m-padded-tb-massive m-opacity" th:replace="_fragments :: footer">
    <!--容器-->
  </footer>

  <script src="../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
  <script src="../../static/lib/Semantic-UI/semantic.min.js" th:src="@{/lib/Semantic-UI/semantic.min.js}"></script>

  <script>

    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
      on : 'hover'
    });

    //消息提示关闭初始化
    $('.message .close')
      .on('click', function () {
        $(this)
          .closest('.message')
          .transition('fade');
      });


    $('#clear-btn')
      .on('click', function() {
        $('.ui.type.dropdown')
          .dropdown('clear');
      });

    function page(obj) {
      $("[name='page']").val($(obj).data("page"));
      loaddata();
    }

    $("#search-btn").click(function () {
      $("[name='page']").val(0);
      loaddata();
    });
    function loaddata() {
      $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
        title : $("[name='title']").val(),
        userId : $("[name='userId']").val(),
        page : $("[name='page']").val()
      });
    }

  </script>
</body>
</html>